package com.jctrip.hotel.source.xxl.atour.thread;

import com.jctrip.hotel.common.constant.RedisKeyConstant;
import com.jctrip.hotel.common.context.BeanContext;
import com.jctrip.hotel.common.util.RedisUtil;
import com.jctrip.hotel.source.service.atour.AtourTaskService;

import lombok.extern.slf4j.Slf4j;

/**
 * @Author henry
 * @Date 2023/6/3 15:36
 * @Description
 */
@Slf4j
public class SyncAtourHotelIdTaskThread implements Runnable {
    private final Integer appId;

    private final String key;
    private static final long SAVE_BATCH = 100;

    public SyncAtourHotelIdTaskThread(Integer appId, String key) {
        this.appId = appId;
        this.key = key;
    }

    @Override
    public void run() {
        try {
            RedisUtil redisUtil = BeanContext.getApplicationContext().getBean(RedisUtil.class);
            AtourTaskService atourTaskService = BeanContext.getApplicationContext().getBean(AtourTaskService.class);
            while (redisUtil.lGetListSize(RedisKeyConstant.HOTEL_MAIN_ATOUR_CITYID_LIST) > 0) {
                try {
                    Integer cityId = (Integer) redisUtil.rightPop(RedisKeyConstant.HOTEL_MAIN_ATOUR_CITYID_LIST);
                    if (null == cityId) {
                        continue;
                    }
                    atourTaskService.syncAtourHotelIdTask(appId, key, cityId);
                } catch (Exception e) {
                    log.error(e.getMessage(), e);
                }
            }

        } catch (Exception e) {
            log.error(e.getMessage(), e);
        }
    }
}